from internal.find import findByGame, findByGaming, findByVac
from internal.search import *



if __name__ == "__main__":
    # 匹配的结果 steamurls
    # steamUrls = []
    # 做挂车的挂钩
    # kw = "残局大师小呆呆"
    kw = "手柄锁"
    sessionid = init.g_sessionID
    steamid_user = init.g_steamID
    params = f'text={kw}&filter=users&sessionid={sessionid}&steamid_user={steamid_user}'
    # 搜索结果
    steamUrls, countTotal = searchSteamUser(params)
    print(f"一共 {countTotal} 匹配结果")
    page = (countTotal // 20) + 1 if countTotal % 20 != 0 else countTotal // 20
    page = page - 5
    print(f"一共 {page} 页")

    # 获取所有匹配搜索结果的steamUrls
    # 异步操作会导致400
    if page > 10:
        # 大于十页放弃搜索
        pass
    else:
        for i in range(page):
            print(f"搜索第{i}页")
            page = i
            params = f'text={kw}&filter=users&sessionid={sessionid}&steamid_user={steamid_user}&page={page}'
            # 搜索结果
            resSteamUrls, _ = searchSteamUser(params)
            for j in resSteamUrls:
                if j not in steamUrls:
                    steamUrls.append(j)

    # # steam 信息
    steamUserInfoList = getSteamInfo(steamUrls,0)
    for i in steamUserInfoList:
        print(i)
    #     匹配到的结果
    # 离线匹配
    # 最近玩过 THE FINALS
    print("最近玩过 THE FINALS")
    # print(findByGame(steamUserInfoList, "THE FINALS"))
    for i in findByGame(steamUserInfoList, "THE FINALS"):
        print(i)
    # 正在玩 THE FINALS
    print("正在玩 THE FINALS")
    # print(findByGaming(steamUserInfoList, "THE FINALS"))
    for i in findByGaming(steamUserInfoList, "THE FINALS"):
        print(i)
    # 有Vac记录
    print('有Vac记录')
    # print(findByVac(steamUserInfoList))
    for i in findByVac(steamUserInfoList):
        print(i)

    # 分析重复好友
    # for i in steamUserInfoList:
    #     print(i)
    #     friendNamesKeyPool, multiFriendPool = analyseFriendship(i["friends"])
    #     print(friendNamesKeyPool, multiFriendPool)
    #     break
